#include <bits/stdc++.h>

using namespace std;

struct huffmannode{
    int metric;
    int freq;
    char c;
    struct huffmannode* left;
    struct huffmannode*right;
} ;
huffmannode a[30];
bool cmp(huffmannode a,huffmannode b){
        if(a.freq!=b.freq)return a.freq<b.freq;
        else return a.c<b.c;
}
string s;
int main()
{
    cin>>s;
    int ls = s.length();
    for(int i=0;i<ls;i++){
        int t;
        huffmannode tt;
        char c = s[i];
        cin>>t;
        tt.c = c;
        tt.freq = t;
        a[i] = tt;
    }
    sort(a,a+ls,cmp);
    for(int i =0;i<ls-1;i++){
        huffmannode t;
        t.c = '-';
        t.freq = a[i].freq+a[i+1].freq;
        t.left = &a[i];
        t.right = &a[i+1];

    }
    return 0;
}
